/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import java.io.*;
import java.net.*;

/**
 *
 * @author Michael
 */
class LeseThread implements Runnable {
static int length = 256;
DatagramSocket socket;

LeseThread(DatagramSocket socket ) {
    this.socket = socket;
    Thread t = new Thread(this,"Lesen");
    t.start();
}

public void run() {
    DatagramPacket packet = new DatagramPacket( new byte[length], length);
    while( true ) {
        try {
            socket.receive( packet );
            InetSocketAddress add = (InetSocketAddress)packet.getSocketAddress();
            String text = new String(packet.getData(), 0, packet.getLength());
            System.out.println("Paket empfangen: "+text);
            int Beginn=0;
            int Ende;
            for(int l=0;l<text.length();l++){
                if(text.charAt(l)==';'){
                    Ende=l;                    
                    System.out.println(text.substring(Beginn,Ende));
                    Beginn=l+1;
                }                
            }
            System.out.println(text.substring(Beginn,text.length()));
            //System.out.println( ">" + text);
        }
        catch( IOException e ) {
            System.err.println("Ausnahmefehler: " + e );
        }
    }
}
}

